//
// Created by 下次一定 on 2021/9/16.
//


#include<iostream>

using namespace std;

const int N = 10;

int n;
// 同一列上 对角线u+i 反对角线n-u+i
bool row[N],col[N], dg[N], udg[N];
char g[N][N];

void dfs(int u) {
    if (u == n) {
        for (int i = 0; i < n; i++) cout << puts(g[i]);
        return;
    }
    for (int i = 0; i < n; i++) {
        if (!col[i] && !dg[u + i] && !udg[n - u + i]) {
            g[u][i] = 'Q';
            col[i] = dg[u + i] = udg[n - u + i] = true;
            dfs(u + 1);
            col[i] = dg[u + i] = udg[n - u + i] = false;
            g[u][i] = '.';
        }
    }

}


void dfs2(int x, int y, int k) {
    if (y == n) y = 0;
    x += 1;
    if (x == n) {
        if (k == n) {
            for (int i = 0; i < n; i++)puts(g[i]);
        }
    }

    // 不放皇后
    dfs2(x, y + 1, k);

    //放皇后
    if (!row[x] && !col[y] && !dg[x + y] && !udg[x - y + n]){
        g[x][y+1];
        row[x] = col[y] = dg[x+y] = udg[x-y+n] = true;
        dfs2(x,y+1,k+1);
        //恢复现场
        row[x] = col[y] = dg[x+y] = udg[x-y+n] = false;
    }
}

int main() {
    cin >> n;
    for (int i = 0; i < n; i++)
        for (int j = 0; j < n; j++)
            g[i][j] = '.';
    dfs(0);
}